<template>
	<view class="page" :style="{minHeight:windowHeight+'px'}">

		<view class="show">
			<view class="select" v-for="(item,index) of bank">
				<view class="select-item">
					<view class="select-content">
						<image class="select-icon" v-if="item.bank_type == 3" src="../../../static/bank.png"></image>
						<image class="select-icon" v-if="item.bank_type == 2" src="../../../static/zfb1.png"></image>
						<image class="select-icon" v-if="item.bank_type == 1" src="../../../static/wx1.png"></image>
						<view class="select-name">
							<!-- <text>1</text>
							<text>2</text> -->
							<text v-if="item.bank_type==3"><text style="margin-right: 10rpx; color: #000000;">{{item.thumbName}}</text>{{item.name}}</text>
							<text v-if="item.bank_type == 1">微信</text>
							<text v-if="item.bank_type == 2">支付宝</text>
							<view class="item-delect">
								<text>{{item.thumb}}</text>
								<image @click="deleteCar(item.id)" src="../../../static/delete.png"></image>
							</view>
						</view>
					</view>
					<!-- <view class="select-tick" v-show="idx==index">
						<image src="../../../../static/tick.png"></image>
					</view> -->
				</view>
			</view>
		</view>
		<!-- 没有记录 -->
		<view class=" d-c-c p30" v-if="bank.length == 0">
			<text class="iconfont icon-wushuju"></text>
			<text class="cont">亲，暂无相关记录哦</text>
		</view>
		<!-- <uni-load-more class="not" v-else :loadingType="loadingType"></uni-load-more> -->
		<view class="add-bank" @click="gotoPath('/pagesUser/user/back-manage/bank-add/bank-add')">
			<image src="../../../static/add.png"></image>
			<text>添加银行卡</text>
		</view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				bank: {},
				windowHeight:''
			};
		},
		onLoad() {
			uni.getSystemInfo({
				success: (res) => {
					this.windowHeight = res.windowHeight
				}
			})
		},
		onPullDownRefresh() {
			setTimeout(() =>{
				uni.stopPullDownRefresh();
			},1000);
			this.getData();
		},
		onShow() {
			this.getData();
		},
		methods: {
			/* 删除 */
			deleteCar(id){
				let self = this;
				console.log(id)
				uni.showModal({
					title:'是否要删除',
					success: function (res) {
					       if (res.confirm) {
					           self._post('user.index/del_bankcard',
					           {
									id:id
					           },
					            function(res) {
					           	
					           });
					       } else if (res.cancel) {
							   
					       }
					   }
				})			 				
			},
			gotoPath(path) {
				let self = this;
				if (path.startsWith('/')) {
					uni.navigateTo({
						url: path,
					});
				} else {
					self[path]();
				}
			},
			/* 获取数据 */
			getData() {
				let self = this;
				uni.showLoading({
					title: '加载中'
				});
				self._post('user.index/bankCard', {}, function(res) {
					self.bank = res.data.bank;
					self.bank.forEach(item =>{
						if(item.bank_type==3){
							var tel = item.bank_code;
							    tel = "" + tel;
							    var newTel = tel.substr(0,4) + " **** **** **** " + tel.substr(15)
							   	item.thumb = newTel
							var reg = /(?<=.)./g;
							var name = item.bank_uname;
								name = "" + name;
								var newname = name.replace(reg,'*');
								item.thumbName = newname;
						}else{
							var tel = item.bank_code;
							    tel = "" + tel;
							    var newTel = tel.substr(0,3) + " **** " + tel.substr(7)
							   	item.thumb = newTel
								
						}						
					})
					self.loadding = false;
					uni.hideLoading();
				});
			},
		}
	}
</script>

<style lang="scss">
	@import 'bank-card.scss';
</style>
